package com.example.fresh_fruit.controller;

import com.example.fresh_fruit.entity.Commodity;
import com.example.fresh_fruit.service.ShoppingCatService;
import com.example.fresh_fruit.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :飞天の鱼
 * @date : 2022/8/24 14:24
 */
@Slf4j
@RestController
@RequestMapping("/ShoppingCat")
public class ShoppingCatController {

    @Autowired
    private ShoppingCatService shoppingCatService;


    @PostMapping("/insert")
    private Result insertShopping(@RequestBody Commodity commodity) {
        int insertShoppingCom = shoppingCatService.insertShoppingCom(commodity);

        switch (insertShoppingCom) {
            case 1:
                return Result.fail("商品的数量不足！");
            case 2:
                return Result.fail("加入购物车失败！");
            case 0:
                return Result.ok("加入购物车成功！");
            default:
        }
        return Result.build(200, "加入购物车成功！");
    }
}
